<?php
namespace app\adminmall\controller;
use think\Controller;
use think\Db;
use app\common\controller\AdminBaseController;
class NewController extends AdminBaseController
{ 
	/**
     * 新闻管理
     * @return mixed
     */
    public function index() {
	    /** 查询数据*/
		$data=Db::name('new')->order('add_time','desc')->select();
        return $this->fetch('index', ['new_list' => $data]);
    }
    /**
     * 新闻增加
     */
	 public function add_new() {
	 	if(input('post.')){
            $param = input('post.');
            $param['add_time']=now_time();
            if(Db::name('new')->insert($param)){
            	return	toSuccess('添加成功');
            }
        }
        $this->assign('list',Db::name('newtype')->select());
        return $this->fetch('add');
    }
    /**
     * 新闻修改
     */
	 public function update_new() {
	 	$id = input('param.id');
	 	var_dump(input('post.'));
	 	if(input('post.')){
            $param = input('post.');
            $param['update_time']=now_time();
            if(Db::name('new')->where('id',$id)->update($param)){
            	return	toSuccess('修改成功');
            }else{
            	 return toError(408,'修改失败，请重新修改');
            }
        }
        $res=Db::name('new')->where('id',$id)->find();
        $this->assign('listnew',$res);
        $this->assign('listname',Db::name('newtype')->where('id',$res['pid'])->find());
	 	$this->assign('list',Db::name('newtype')->select());
	 	
	 	
        return $this->fetch('update');
        
    }
    /**
     * 新闻删除
     */
	 public function del_new() {
        if (Db::name('new')->where('id',input('param.id'))->delete()) {
           return	toSuccess('删除成功');
        } else {
            return toError(408,'删除失败，请重新删除');
        }
    }
	  
}
?>